tg-me.com/python_codes/6
Last Update:
3. Determining variable type with type()
>> a=7
>>> type(a)
<class 'int'>
>>> b=7.7
>>> type(b)
<class 'float'>
>>> c="hello"
>>> type(c)
<class 'str'>
>>> d=[1,2,3]
>>> type(d)
<class 'list'>
>>> e=(1,2,3)
>>> type(e)
<class 'tuple'>
>>> f={1:"one",2:"two"}
>>> type(f)
<class 'dict'>
>>> g={1,2,3}
>>> type(g)
<class 'set'>
>>> i=True
>>> type(i)
<class 'bool'>
You can check what type of object is assigned to a variable using Python's built-in type() function. Common data types include:
int (for integer)
float
str (for string)
list
tuple
dict (for dictionary)
set
bool (for Boolean True/False)
@python_codes
BY Python Codes
Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283
Share with your friend now:
tg-me.com/python_codes/6